package com.lam.mall.service.impl;

import java.util.List;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.lam.common.utils.StringUtils;
import org.springframework.stereotype.Service;
import com.lam.mall.mapper.TransFreeCityMapper;
import com.lam.mall.entity.TransFreeCity;
import com.lam.mall.param.TransFreeCityParam;
import com.lam.mall.service.TransFreeCityService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * 包邮城市Service业务层处理
 * 
 * @author admin
 * @date 2023-04-21
 */
@Service
public class TransFreeCityServiceImpl  implements TransFreeCityService {

    @Autowired
    private TransFreeCityMapper transFreeCityMapper;

    /**
     * 查询包邮城市
     * 
     * @param id ID
     * @return 单个对象
     */
    @Override
    @Transactional(readOnly = true)
    public TransFreeCity selectById(String id) {

        return transFreeCityMapper.selectById(id);
    }

    /**
     * 查询包邮城市列表
     * 
     * @param param
     * @return 
     */
    @Override
    @Transactional(readOnly = true)
    public List<TransFreeCity> selectList(TransFreeCityParam param) {
    
        QueryWrapper<TransFreeCity> queryWrapper = new QueryWrapper<>();
        
        queryWrapper.eq(Objects.nonNull(param.getTransFreeId()), "trans_free_id", param.getTransFreeId());
        queryWrapper.eq(Objects.nonNull(param.getCityId()), "city_id", param.getCityId());

        return transFreeCityMapper.selectList(queryWrapper);
    }

    /**
     * 新增包邮城市
     * 
     * @param transFreeCity 
     * @return 
     */
    @Override
    @Transactional
    public int insert(TransFreeCity transFreeCity) {
    
        return transFreeCityMapper.insert(transFreeCity);
    }

    /**
     * 修改包邮城市
     * 
     * @param transFreeCity 
     * @return 
     */
    @Override
    @Transactional
    public int update(TransFreeCity transFreeCity) {
    
        return transFreeCityMapper.updateById(transFreeCity);
    }

    /**
     * 删除包邮城市信息
     * 
     * @param idStr ID，多个用逗号分隔
     * @return 
     */
    @Override
    @Transactional
    public int deleteById(String idStr) {
    
        if(StringUtils.isBlank(idStr)) {
            return 0;
        }
        return transFreeCityMapper.deleteBatchIds(StringUtils.str2List(idStr));
    }
    
    
}
